<template>
 <div style="width:80%">
   <el-card style="max-width: 1000px">
    <template #header>
      <div class="card-header" style="text-align: center">
        <span>发表微博</span>
      </div>
    </template>
    <div>
        <el-form  label-width="auto" style="max-width: 1000px">
            <el-form-item label="标题">
            <el-input v-model="title" />
            </el-form-item>
            <el-form-item label="图片">
            <input type="file"  ref="xx"/>
            </el-form-item>
            <el-form-item label="内容">
            <el-input type="textarea" v-model="content" />
            </el-form-item>
        </el-form>
    </div>
    <template #footer>
      <div style="text-align: center">
             <el-button type="primary" @click="publish">发表</el-button>
             <el-button>取消</el-button>
      </div>
    </template>
  </el-card>
   
  </div>
</template>

<script>
import axios from '@/axios/index.js';
export default {
   data(){
      return {
         title:'',
         content:'',
      }
   },
  //  beforeCreate(){
  //     if(sessionStorage.getItem("curUser")==null){
  //        alert("请先登录");
  //        this.$router.push("/login");
  //     }
  //  },
   methods:{
      publish:function(){
        alert(this.title);
        console.log(this.$refs.xx)
        var fd=new FormData();
         fd.append("title",this.title);
         fd.append("content",this.content);
         fd.append("pic",this.$refs.xx.files[0]);
        axios.post("http://localhost:81/my/ajax/wb/add",fd,{
          headers: {
            'Content-Type':'multipart/form-data'
          }})
        .then(function(resp){
               alert(resp.data.msg)
        });
      }
   }
}
</script>

<style>

</style>